class AtestFailTops:
    def __init__(self):
        self.fail_tops = {}

    def add_item(self, main_id:str):     # 每次测试出现fail都应该记录
        if main_id in self.fail_tops.keys():
            self.fail_tops[main_id] = self.fail_tops[main_id] + 1
            print('加1')
        else:
            self.fail_tops[main_id] = 0
            print('归0')

    def add_main_case_init(self, main_id):
        self.fail_tops[main_id] = 0

    def add_main_cases_init(self, l:list[str]):
        for i in l:
            self.fail_tops[i] = 0

    def get_fail_top_dict(self):
        return self.fail_tops

    def get_sorted(self):
        # 返回值为[(id, num), (id, num)...]
        return sorted(self.fail_tops.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)